package com.java.study.api;

import com.java.study.DTO.StudentDTO;
import com.java.study.api.constants.Constant;
import com.java.study.entity.StudentPO;
import com.java.study.modules.Result;
import com.java.study.modules.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:StudentInfoController
 * Description:
 *
 * @Date:2022/8/29 11:25
 * @Author:chenruifeng
 */
@Slf4j
@RestController
public class StudentInfoController {

    @Autowired
    private IStudentService IStudentService;

    @GetMapping("student/findStudentInfo")
    public Result<StudentPO> queryInfoByName(@RequestParam String name) {
        Result<StudentPO> result = new Result<>();
        StudentPO byNames = IStudentService.findByNames(name);
        if (byNames == null) {
            result.setMessage("查询结果为空！");
        }else {
            result.setCode(Constant.SC_OK_200);
            result.setResult(byNames);
        }

        return result;
    }

    @PostMapping("student/batchInsert")
    public void batchInsert(@RequestBody StudentDTO studentDTO){
        IStudentService.batchInsert(studentDTO);
    }
}
